package com.journaldev.threadpool.runner;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author: chenhs
 * @date: Created in 6:37 2019/9/17
 **/
public class Runner implements Callable<Integer> {
    /** 裁判*/
    private CountDownLatch begin;
    /** 跑步*/
    private CountDownLatch end;

    public Runner(CountDownLatch begin, CountDownLatch end) {
        this.begin = begin;
        this.end = end;
    }

    @Override
    public Integer call() throws Exception {
        int score = new Random().nextInt(10);
        //裁判等待运动员上场
        begin.await();
        //跑步比赛（跑步耗时）
        TimeUnit.MILLISECONDS.sleep(score);
        //运动员跑步完成
        end.countDown();

        return score;
    }
}
